Page({
    data: {
        showPwd: false, //密码是否可见
        pwdType: 'password',
        btnLoading: false,
        pwdText: '',
    },

    onLoad(options) {},

    onTapPwdicon() {
        if (this.data.showPwd) {
            this.setData({
                pwdType: 'password',
            });
        } else {
            this.setData({
                pwdType: 'text',
            });
        }
        this.setData({
            showPwd: !this.data.showPwd,
        });
    },
    onInput(e) {
        this.setData({
            pwdText: e.detail.value,
        });
    },

    submit() {
        if (!this.data.pwdText)
            return wx.showToast({
                title: '请设置密码',
                icon: 'none',
            });
        this.setData({
            btnLoading: true,
        });
        this.request({
            url: 'user/my/safety/setPassword',
            method: 'POST',
            data: {
                type: 2,
                password: this.data.pwdText,
            },
        })
            .then(async res => {
                this.setData({
                    btnLoading: false,
                });
                wx.showToast({
                    title: res.msg,
                });

                await this.sleep(1000);
                wx.switchTab({
                  url: '/pages/user/user',
                })
            })
            .catch(err => {
                this.setData({
                    btnLoading: false,
                });
            });
    },
});
